/**
 * Created by Administrator on 2018/11/3.
 */
var User = require("../models/users");
/**
 * 注册
 */

module.exports = function (name, psw, response) {

  let wherestr = {
    'username': name,
    'pass': psw
  };

  var data = User.find(wherestr, function (err, res) {
    if (err) {
      console.log("Error:" + err);
    }
    if (res.length !== 0) {

      response.cookie('username', name, {
        maxAge: new Date(new Date()),
        httpOnly: true
      }) // 设置 cookie 与 httpOnly

      response.json({
        status: 0,
        data: {
          msg: '登陆成功!',
          username: name,
        }
      });
      return true;
    } else {
      response.json({
        status: 1,
        data: {
          msg: '账号或密码错误!'
        }
      });
      return false;
    }
  })
  return data;
}
